import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/HomeView.vue'
import CartView from '@/views/CartView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home', //重定向到Home页
    },
    {
      path: '/home',
      name: 'Home',
      meta: {
        keepAlive: true,
      },
      component: HomeView,
    },
    {
      path: '/live',
      name: 'Live',
      component: () => import('@/views/LiveView.vue'),
    },
    {
      path: '/shopping',
      name: 'Shopping',
      component: () => import('@/views/ShoppingView.vue'),
    },
    {
      path: '/my',
      name: 'My',
      component: () => import('@/views/MyView.vue'),
    },
    {
      path: '/cart',
      name: 'Cart',
      component: CartView,
    },
    {
      path: '/order',
      name: 'Order',
      component: () => import('@/views/OrderView.vue'),
    },
    {
      path: '/search',
      name: 'Search',
      component: () => import('@/views/Search.vue'),
      redirect: {
        name: 'SearchIndex',
      },
      children: [
        {
          path: '/',
          name: 'SearchIndex',
          component: () => import('@/components/Search/SearchIndex.vue'),
        },
        {
          path: '/list',
          name: 'SearchList',
          component: () => import('@/components/Search/SearchList.vue'),
        },
      ],
    },
    {
      path: '/detail',
      name: 'Detail',
      meta: {
        keepAlive: true,
      },
      component: () => import('@/views/Detail.vue'),
    },
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/components/My/Login.vue'),
    },
    {
      path: '/register',
      name: 'Register',
      component: () => import('@/components/My/Register.vue'),
    },
    {
      path: '/modify',
      name: 'ModifyPassword',
      component: () => import('@/components/My/Modify.vue'),
    },
  ],
})

export default router
